package com.member.server.controller;

import com.member.server.domain.Result;
import com.member.server.domain.param.AccountCreateParam;
import com.member.server.domain.param.MemberSaveParam;
import com.member.server.service.IMemberBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author gaojx1993
 * @version 1.0
 * @description MemberController
 * @since 2023/7/11 15:38
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private IMemberBizService memberBizService;

    @PostMapping("save")
    public Result<Long> saveMember(@RequestBody MemberSaveParam memberSaveParam) {
        if (StringUtils.isBlank(memberSaveParam.getName())) {
            return Result.fail("姓名不能为空");
        }
        return Result.success(memberBizService.saveMember(memberSaveParam));
    }

    @PostMapping("create-account")
    public Result<Long> createAccount(@RequestBody AccountCreateParam accountCreateParam) {
        if (accountCreateParam.getMemberId() == null) {
            return Result.fail("会员id不能为空");
        }
        return Result.success(memberBizService.createAccount(accountCreateParam));
    }
}
